// VolumeGenerator.cpp: implementation of the VolumeGenerator class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "VolumeGenerator.h"
#include "DlgNewvolume.h"
#include "ProjectManager.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

VolumeGenerator& GetVolumeGenerator(){
	ASSERT(GetProjectManager().CurProject());
	ASSERT(GetProjectManager().CurProject()->versionController());
	return GetProjectManager().CurProject()->versionController()->CurVolumeGenerator();
}

namespace VersionControl
{
	IMPLEMENT_SINGLETON(VolumeGenerator)
		
	VolumeGenerator::VolumeGenerator()
	{
		
	}
	
	VolumeGenerator::~VolumeGenerator()
	{
		
	}
	
	Volume* VolumeGenerator::Generate()
	{
		Volume* pVolume = new Volume;
		ASSERT(pVolume);
		
		CDlgNewVolume dlg(pVolume);
		if(dlg.DoModal() == IDCANCEL)
		{
			delete pVolume;
			return NULL;
		}
		ASSERT(project());
		pVolume->project(project());
		return pVolume;
	}

	Volume* VolumeGenerator::Generate(RecordsetPtrWrap& rs)
	{
		ASSERT(!rs.IsBOF() && !rs.IsEOF());

		Volume* pVolume = new Volume;
		ASSERT(pVolume);

		pVolume->VolumeID(rs.GetInt(_T("VolumeID")));
		pVolume->Name(rs.GetString(_T("VolumeName")));
		pVolume->Description(rs.GetString(_T("Description")));
		pVolume->SetRead();

		ASSERT(project());
		pVolume->project(project());

		return pVolume;
	}
}